/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.modeldocument.primitives;

import dgbgui.modeldocument.ModelDocument;


public abstract class Conceptron  extends Primitive {

    public long m_typeID = (long)0;
    public Attribute m_attributes[] = null;

    public Conceptron(long id, long typeID, Attribute[] attributes) {
        super(id);
        m_typeID = typeID;
        m_attributes = attributes;
    }
    
    public abstract String getDGBQLForPrimitive();
    
    public String getDGBQLForPrimitiveAfterColon() {
        ConceptronType type = ModelDocument.getInstance().getConceptronType(this);
        AttributeType identAttrType = ModelDocument.getInstance().getIdentifierAttributeType(type);
        // If the is an identifier attribute, use its name and value
        // to identify the instance in a dgbQL string
        if ( identAttrType != null ) {
            for ( Attribute attr : m_attributes ) {
                if ( attr.m_id == identAttrType.m_id ) {
                    return type.m_name + "." + identAttrType.m_name + "[" + attr.m_value + "]";
                }
            }
        }
        return null;
    }
    
    public boolean isScemataIdentifier() {
        for ( Attribute attr : m_attributes ) {
            AttributeType attrType = ModelDocument.getInstance().getAttributeType(attr);
            if ( attrType.m_name.equalsIgnoreCase("name") ) {
                String name = attr.m_value.toString();
                if ( name.startsWith("|") && name.endsWith("|") ) {
                    return true;
                }   
            }
        }
        return false;
    }
    
    
    // ---------------- Serialization ------------
    
    /**
     * First serilization version
     */
    private static final long serialVersionUID = 1L;
    


    
}
